package com.itheima;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("1");
        collection.add("2");
        collection.add("2");
        collection.add("4");
        collection.add("5");

        //迭代器循环
        Iterator<String> iterator = collection.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//
//        }
        //迭代器删除
        while (iterator.hasNext()){
           if ("2".equals(iterator.next())){
               iterator.remove();
           }

        }

        //增强for循环
        for (String s : collection) {
            System.out.print(s);

        }
    }
}
